package com.lixixi.tingshu.album.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lixixi.tingshu.album.mapper.AlbumStatMapper;
import com.lixixi.tingshu.album.service.AlbumStatService;
import com.lixixi.tingshu.model.album.AlbumStat;
import com.lixixi.tingshu.vo.album.AlbumStatVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class AlbumStatServiceImpl extends ServiceImpl<AlbumStatMapper, AlbumStat> implements AlbumStatService {
	@Autowired
	AlbumStatMapper albumStatMapper;

	@Override
	public AlbumStatVo getAlbumStatById(Long id) {
		return albumStatMapper.selectAlbumStatById(id);
	}

	@Override
	public Map<Long, List<AlbumStatVo>> getAlbumStatByIdBatch(List<Long> albumIdList) {
		List<AlbumStatVo> albumStatVoList = albumStatMapper.selectAlbumStatByIdBatch(albumIdList);
		Map<Long, List<AlbumStatVo>> albumStatVoMap = albumStatVoList.stream().collect(Collectors.groupingBy(AlbumStatVo::getAlbumId));
		return albumStatVoMap;
	}

	@Override
	public void updateAlbumStat(String statType, Integer count, Long albumId) {
		albumStatMapper.updateAlbumStat(statType, count, albumId);
	}


}
